package com.ly.lypopupwindowdemo.decoration;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ly.lypopupwindowdemo.R;

/**
 * Created by liying on 2017/5/26.
 */

public class SimplePaddingDecoration extends RecyclerView.ItemDecoration {

    /**
     * ItemDecoration类主要是三个方法：
     * <p>
     * public void onDraw(Canvas c, RecyclerView parent, State state)可以实现类似绘制背景的效果，内容在上面
     * public void onDrawOver(Canvas c, RecyclerView parent, State state)可以绘制在内容的上面，覆盖内容
     * public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state),可以实现类似padding的效果
     *
     *
     * getItemOffsets也可以实现分割线的功能，但是只能是recycleView的背景色，不能自定义颜色，所以分割线根据onDraw来实现
     * 参考SimpleDividerDecoration类
     *
     */
    private int dividerHeight;

    public SimplePaddingDecoration(Context context) {
        dividerHeight = context.getResources().getDimensionPixelSize(R.dimen.divider_height);
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.bottom = dividerHeight;//类似加了一个bottom padding
    }
}
